<?php 
	error_reporting(0);
	include $_SERVER["DOCUMENT_ROOT"].'/app/application.php';	
	
	# tweet sharing
	if ( isset($_POST['username']) )
	{
		$username = $_POST['username'];
		$password = $_POST['password'];
		$tweet = $_POST['tweet'];	

		$app->tweet($username, $password, $tweet);
	};

	# creating shorten link
	if (isset($_POST['url']))
	{
	  $short = $app->addUrl($_POST['url']);
	  $shortenedLink = $app->config->domain;
	  $shortenedLink.= $short;
	  $url = '<a  id="toClipboard" href = "'.$shortenedLink.'">'.$shortenedLink.'</a>';
	};
	
	# creating shorten link
	if (isset($_GET['url']))
	{
		$url = $_GET['url'];
		$url = str_replace( "&", ":amp:",$url);
		$url = str_replace( "=", ":eq:",$url);
		$url = str_replace( "?",":que:", $url);
	  $short = $app->addUrl($url);
	  $shortenedLink = $app->config->domain;
	  $shortenedLink.= $short;
	  $url = '<a  id="toClipboard" href = "'.$shortenedLink.'">'.$shortenedLink.'</a>';
	};
	
	# redirecting
	if (isset($_GET['link']) && 
	          $_GET['link'] != 'index.php' && 
			  $_GET['link'] != '')
	{
		$shortUrl = $_GET['link'];				
		$longUrl = $app->searchLongUrl($shortUrl);
		$app->visit($longUrl); 	
		header('Location: http://'.$longUrl );
	};
?>
	
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
	<head>
		<title>Squeez</title>
		<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/reset-fonts-grids/reset-fonts-grids.css"> 
		<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/fonts/fonts-min.css" />
		<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/button/assets/skins/sam/button.css" />
		<link rel="stylesheet" type="text/css" href="http://yui.yahooapis.com/2.8.1/build/container/assets/skins/sam/container.css" />
		   <link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Droid">
		<link rel="stylesheet" type="text/css" href="public/css/style.css">
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/yahoo/yahoo-min.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/event/event-min.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/yahoo-dom-event/yahoo-dom-event.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/connection/connection-min.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/element/element-min.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/button/button-min.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/dragdrop/dragdrop-min.js"></script>
		<script type="text/javascript" src="http://yui.yahooapis.com/2.8.1/build/container/container-min.js"></script>
		<script type="text/javascript" src="public/scripts/tweet-dialog.js"></script>		
	</head>
	
	<body class="yui-skin-sam" bgcolor=#FFFFFF style="font-family: 'Droid', serif; font-size: 16px;">
		<!-- #doc = 750px; #doc2 = 950px; #doc3 = 100%; #doc4 = 974px -->
		<div id="doc">					
			<div id="hd">
				<br /><br />
				<div id='alert-zone'></div>	
				<table width = 90% align=right> 
					<tr>
						<td align=left><a href="<?php echo $app->config->domain; ?>"><img src="public/img/logo_small.png" /></a></td>
						<td><a href="index.php">Home</a></td>
						<td><a href="http://madundead.is-a-geek.org/squeez-storage/">Music</a></td>
						<td><a href="#">About</a></td>
					</tr>
				</table>
			</div>					

			<div id="dialog1" class="yui-pe-content">
				<div class="hd">Share via Twitter</div>
				<div class="bd">
					<form method="POST" action="index.php">
						<label for="username">Username:</label><input type="textbox" name="username" />
						<label for="password">Password:</label><input type="textbox" name="password" /><br />					
						<label for="textarea"><br />Tweet:<br /></label><textarea name="tweet" 
						rows=4 cols=50><?php echo $app->config->domain.$short; ?></textarea>
						
					</form>								
				</div>								
			</div>

			<div id="bd">
			<table valign=top align=center width=950>
				<tr>
						<center>
						<br /><br /><br /><br /><br /><br /><br />
							<form action="index.php" method="post">
							URL: <input type="text" name="url" size=70 />									
							<input type="submit" value="   Squeez   "/>							
							</form>
							<?php 
							if ( isset($url) || isset($short) ) $app->showLink($url, $short); ?> 
						<br /><br /><br /><br /><br /><br /><br /><br /><br />
						</center>
				</tr>
				<tr>
					<td>
						<?php $app->showShortened(); ?>
					</td>
					<td width=2%></td>
					<td>
						<?php $app->showTop(); ?>
					</td>
				</tr>
			</table>
			</div>
			
			<br /><br /><br />
			<div id="ft"><center>made by madundead & lise-lotta. 2010</center></div>
	</body>
	
</html>
